/* 
 * Enterprise Library Extensions - DI + ORM.
 * Copyright (C) 2006
 *
 * GNU General Public License
 *
 * This program is free software; you can redistribute 
 * it and/or modify it under the terms of the GNU General Public License 
 * as published by the Free Software Foundation; either version 2 of the 
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 * See the GNU General Public License for more details.
 */
using System;
using System.Collections;
using System.Xml.Serialization;
using ELE.Common.Util;

namespace ELE.EnterpriseLibrary.Aspects.Sinks
{
	/// <summary>
	/// Summary description for Aspects.
	///
	/// Author: Miguel Curi
	///
	/// </summary>
	[XmlRoot("aspects")]
	public class AspectsTable
	{
    private Hashtable aspects;
    /// <summary>
    /// Aspects table constructor
    /// </summary>
		public AspectsTable()
		{
		}
    /// <summary>
    /// Read a config file and return an object of this type
    /// </summary>
    /// <param name="location"></param>
    /// <returns></returns>
    public static AspectsTable Read(string location)
    {
      return (AspectsTable) XML.DeSerializeObject(typeof(AspectsTable), location);
    }
    /// <summary>
    /// List of aspects
    /// </summary>
    [XmlElement("aspect")]
    public AspectAdvise[] AspectsList
    {
      set
      {
        aspects = new Hashtable();
        foreach(AspectAdvise advise in value)
        {
          aspects.Add(advise.MethodName, advise.Advices);
        }
      }
      get
      {
        AspectAdvise[] advices = new AspectAdvise[aspects.Count];
        int cnt = 0;
        foreach(string key in aspects.Keys)
        {
          AspectAdvise advise = new AspectAdvise();
          advise.MethodName = key;
          advise.Advices = (AspectConfigurationList)aspects[key];
          advices[cnt] = advise;
          cnt++;
        }
        return advices;
      }
    }
    /// <summary>
    /// Adds advise
    /// </summary>
    /// <param name="advise"></param>
    public void Add(AspectAdvise advise)
    {
      if(aspects == null)
      {
        aspects = new Hashtable();
      }
      aspects.Add(advise.MethodName, advise.Advices);
    }
    /// <summary>
    /// Aspects list
    /// </summary>
    [XmlIgnore]
    public Hashtable Aspects
    {
      get { return aspects; }
    }
	}
}
